package android.slc.appbase.ui.activity.base;

import android.os.Bundle;
import android.slc.appbase.R;
import android.slc.appbase.config.ConstantsBase;
import android.slc.appbase.vm.AppBaseViewModel;
import android.slc.toolbar.ISlcToolBarDelegate;
import android.slc.toolbar.SlcToolBarDelegate;

import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.widget.Toolbar;
import androidx.databinding.ViewDataBinding;

import com.blankj.utilcode.util.StringUtils;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.color.MaterialColors;

public abstract class AppMvvmBaseToolBarActivity<V extends ViewDataBinding, VM extends AppBaseViewModel> extends AppMvvmBaseActivity<V, VM> {
    protected Toolbar mSlcToolbar;

    protected String getTitleByIntent(String defTitle) {
        String titleByIntent = getIntent().getStringExtra(ConstantsBase.Key.KEY_TITLE_LABEL);
        if (StringUtils.isEmpty(titleByIntent)) {
            titleByIntent = defTitle;
        }
        return titleByIntent;
    }

    protected String getTitleByIntent(@StringRes int defTitleId) {
        return getTitleByIntent(StringUtils.getString(defTitleId));
    }


    @Override
    public void onBindView(@Nullable Bundle savedInstanceState) {
        super.onBindView(savedInstanceState);
        mSlcToolBarDelegate.setToolBarElevation(0);
        mSlcToolbar = mSlcToolBarDelegate.getToolBar();
        mSlcToolbar.setNavigationIcon(R.drawable.ic_slc_native_back);
        mSlcToolbar.setNavigationOnClickListener(l -> onBackPressed());
        mSlcToolBarDelegate.getTitleTextView().setTextSize(18);
        mSlcToolBarDelegate.getSubTitleTextView().setTextSize(12);

        AppBarLayout appBarLayout = mSlcToolBarDelegate.getAppBarLayout();
        appBarLayout.setBackgroundColor(MaterialColors.getColor(appBarLayout,R.attr.colorSurface));
        appBarLayout.setPadding(appBarLayout.getPaddingLeft(), mSlcToolBarDelegate.getStatusBarHeight() + appBarLayout.getPaddingTop(),
                appBarLayout.getPaddingRight(), appBarLayout.getPaddingBottom());
    }

    @Override
    protected ISlcToolBarDelegate onInitSlcToolBarDelegate() {
        return new SlcToolBarDelegate.Builder(this).build();
    }
}
